package com.abtu.sms.teacher.handler;


import com.abtu.sms.pojo.Course;
import com.abtu.sms.pojo.Teacher;
import com.abtu.sms.teacher.service.TeacherService;
import com.abtu.sms.teacher.service.impl.TeacherServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;

@Controller
@RequestMapping("/teacher")
public class TeacherHandler {
    @Resource
    private TeacherService teacherService;

    @PostMapping ("/login")
    public String login(String id, String password, HttpServletRequest request) {
        try {
            Teacher teacher=teacherService.login(id,password);
            if (null != teacher) {
                request.getSession().setAttribute("teacher", teacher);
                // 保存老师的tid
                request.getSession().setAttribute("tid", teacher.getTid());
                System.out.println("xxxxxxxxxxxvvvvvvvvvvvvvvvvvvvv" + teacher.getTname());
                request.getSession().setAttribute("tname", teacher.getTname());
                request.getSession().setAttribute("tsex", teacher.getTsex());
                request.getSession().setAttribute("teducation", teacher.getTeducation());
                request.getSession().setAttribute("ttitle", teacher.getTtitle() );
                return "redirect:tIndex.jsp";
            }
        }catch (Exception exception){
            exception.printStackTrace();
            return null;
        }
        return null;
    }
    @GetMapping  ("/logout")
    public String login(HttpServletRequest request) {
        request.getSession().invalidate();
        return "redirect:../login.jsp";
    }
}
